var fileSystem = require('fs');
var path = require("path");
var url = require("url");
var locationController = require("./controllers/LocationController.js");
var unitController = require("./controllers/unitController.js");
module.exports = {
    mappings: [{
        mappingName: "/views/*",
        methodType: 'GET',
        method: function(req, res) {
            var dataToSend;
            var uri = url.parse(req.url).pathname;
            var filename = path.join(process.cwd(), uri);
            fileSystem.readFile(filename, function(err, data) {
                if (err) {
                    res.send(err);
                }
                else {
                    res.contentType(filename);
                    dataToSend = data;
                    res.send(dataToSend);
                }
            });
        }
    },{
        mappingName: "/units/read",
        methodType: 'GET',
        method: function(req, res) {
            var obj=req.body;
             unitController.read(function(result) {
                res.send(result);
            }, function(err){
                res.send(err);
            }) ;
        }
    },
    {
        mappingName: "/locations/put",
        methodType: 'POST',
        method: function(req, res) {
            var obj=req.body;
            console.log(obj);
            locationController.save(obj, function(result) {
                res.send(result);
            }, function(err) {
                res.send(err);
            });
        }
    }, {
        mappingName: "/locations/read",
        methodType: 'GET',
        method: function(req, res) {
            locationController.read(function(result) {
                res.send(result);
            }, function(err){
                res.send(err);
            }) ;
        }
    },
     {
        mappingName: "/locations/delete",
        methodType: 'POST',
        method: function(req, res) {
               var obj=req.body;
            console.log(obj);
            locationController.deleteEntry(obj,function(result) {
                res.send(result);
            }, 
            function(err){
                res.send(err);
            });
        }
    }
    ]

};